//
//  NewChangeYanZhengViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/30.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewChangeYanZhengViewController.h"
#import "JTCSM.h"
#import "PayBankListTableViewCell.h"
#import "MyInfoView.h"
#import "NewChangeSecondYZViewController.h"

@interface NewChangeYanZhengViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tableview;
    NSMutableArray *titlearray;
}

@end

@implementation NewChangeYanZhengViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    [df isRemoveTarbar:YES];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];

    [self layoutTableView];
    [self theRequest];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
}

- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight)];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    _tableview.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return titlearray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"iii%ld",(long)indexPath.row];
    
    PayBankListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[PayBankListTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid celltype:IsDefaultCellType];
    }
    if (indexPath == nil || indexPath.row>=titlearray.count) {
        return cell;
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell setvalueWithModel:titlearray[indexPath.row]];
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [PayBankListTableViewCell whc_CellHeightForIndexPath:indexPath tableView:tableView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    MyInfoView *view2 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KagainChangeHeight, KCONTROLLERWith, 50) imagename:@"绑定银行卡icon.png" title:@"重新绑定银行卡找回" placeholder:nil isShowLabel:labelType radioBtnIndex:0 GroupId:@""];
    view2.label.frame = CGRectMake(view2.label.LC_x, view2.label.LC_y, KCONTROLLERWith, view2.label.LC_height);
    return view2;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MyBankCardModel *model = titlearray[indexPath.row];
    NewChangeSecondYZViewController *vc = [[NewChangeSecondYZViewController alloc]init];
    vc.nameTitle = @"安全验证";
    vc.model = model;
    [self.navigationController pushViewController:vc animated:YES];}

- (void)theRequest{
    [titlearray removeAllObjects];
    titlearray = nil;
    titlearray = [NSMutableArray array];
    
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"CreditCard/index") withDict:@{@"token":KTokenString} superView:nil isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
            NSArray *bannerArr = KResultOfKey(@"data");
            for (NSDictionary *bannerdict in bannerArr) {
                MyBankCardModel *model = [MyBankCardModel whc_ModelWithJson:bannerdict];
                [titlearray addObject:model];
            }
            
            [_tableview reloadData];
        }
    }];
}

@end
